﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KeepAnimals.BLL;
using KeepAnimals.UI;
namespace KeepAnimals.UI
{
    public partial class FormAddAnimal : Form
    {
        private int IdBox;
        static private Home _form;
        private int _idDepartment;

        public int IdDepartment
        {
            get { return _idDepartment; }
            set { _idDepartment = value; }
        }

        public Home Form1
        {
            get { return _form; }
            set { _form = value; }
        }
        public FormAddAnimal(int idBox, int idDepartment)
        {
            IdBox = idBox;
            _idDepartment = idDepartment;
            InitializeComponent();
            comboBox_type.Items.Add("Chat");
            comboBox_type.SelectedIndex = 0; //set the first item as select item
            comboBox_type.Items.Add("Chien");

            comboBox_states.Items.Add("Egaré");
            comboBox_states.SelectedIndex = 0; //set the first item as select item
            comboBox_states.Items.Add("A adopter");

            comboBox_atdress.Items.Add("Oui");
            comboBox_atdress.SelectedIndex = 0; //set the first item as select item
            comboBox_atdress.Items.Add("Non");

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void FormAddAnimal_Load(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void label10_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {

        }

        private void button_add_animal_database_Click(object sender, EventArgs e)
        {

            //string type = comboBox_type.Selected;
            string type = comboBox_type.Text;
            //MessageBox.Show("Il s'agit d'un : " + type);

            string name = TextBox_name.Text;
            // check field  age is correct
            if (name != "")
            {
                //MessageBox.Show("\nson nom est : ");
            }
            else
            {
                //MessageBox.Show("\nErreur : le nom n'est pas correct");
            }

            //string age = TextBox_age.Text;
            string age = TextBox_age.Text;
            // check field  age is correct
            if (Convert.ToInt32(age) > 0)
            {
                //MessageBox.Show("\nson age est : " + age);
            }
            else
            {
                //MessageBox.Show("\nErreur : l'age n'est pas supérieur à 0");
            }

            string weight = textBox_weight.Text;
            //MessageBox.Show("\nson poids est : " + weight);

            string description = richTextBox_description.Text;
            //MessageBox.Show("\nsa description est : " + description);

            string states = comboBox_states.Text;
            //MessageBox.Show("\nson etat est : " + states);

            string atdress = comboBox_atdress.Text;
            //MessageBox.Show("\n a dresse : " + atdress);

            string date = dateTimePicker1.Text;
            //MessageBox.Show("\nla date d arrivee est : " + date);

            string reason = richTextBox_reason.Text;
            //MessageBox.Show("\nla raison est : " + reason);
            string caption = "Souhaitez-vous ajouter un animal?";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;
            result = MessageBox.Show("Il s'agit d'un : " + type
                            + "\nson nom est : " + name
                            + "\nson age est : " + age
                            + "\nson poids est : " + weight
                            + "\nsa description est : " + description
                            + "\nson etat est : " + states
                            + "\n a dresse : " + atdress
                            + "\nla date d arrivee est : " + date
                            + "\nla raison est : " + reason
                            , caption, buttons);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                //MessageBox.Show("clic sur oui");
                // Closes the parent form.
                Animal animal;
                if (type == "Chat")
                {
                     animal = AnimalFactory.CreateAnimal(Animal.ANIMAL_CAT);
                }
                else
                {
                     animal = AnimalFactory.CreateAnimal(Animal.ANIMAL_DOG);
                }
                animal.Name = name;
                animal.Age = Int32.Parse(age);
                animal.Weight = double.Parse(weight);
                animal.Description = description;
                animal.State = states;
                animal.IdBox = IdBox;
                
                animal.Id = animal.AddAnimalInDatabase();

                Box box = new Box();
                box.Id = IdBox;
                box.IdAnimal = animal.Id;
                box.Empty = Box.BOX_FULL;
                box.UpdateIDAnimalInDatabaseWithIdBox();
                //Animal.UpdateIDAnimalInDatabaseWithIdBox();
                //Form1.Refresh();
                //Form1.LoadBox();
                this.Close();
                
                //FormAddAnimal.c
            }
            else
            {
                this.Close();
            }


            //string type = comboBox_type.GetItemText();

            //int pro_sit_id = (int)this.comboBox_situation_pro_generale.SelectedValue;
        }

        static public void ReturnForm(Home form)
        {
            _form = form;
        }
    }
}
